﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace DaveSexton.Labs
{
	public sealed class BooleanToVisibilityConverter : IValueConverter
	{
		#region Public Properties
		public Visibility TrueValue
		{
			get;
			set;
		}

		public Visibility FalseValue
		{
			get;
			set;
		}
		#endregion

		#region Private / Protected
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="BooleanToVisibilityConverter" /> class.
		/// </summary>
		public BooleanToVisibilityConverter()
		{
			TrueValue = Visibility.Visible;
			FalseValue = Visibility.Collapsed;
		}
		#endregion

		#region Methods
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			bool flag = false;

			if (value is bool)
			{
				flag = (bool) value;
			}
			else if (value is bool?)
			{
				flag = (bool?) value ?? false;
			}

			return flag ? TrueValue : FalseValue;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return value is Visibility && (Visibility) value == TrueValue;
		}
		#endregion
	}
}